<?php
/////////////////////////////////////////////////////////////////////////////
// 
//
// workflow_system 
//
// workflow_copyright
// 
/////////////////////////////////////////////////////////////////////////////

/**
 * FILE_NAME : predeposit.class.php   FILE_PATH : E:\www\\trunk\classes\application\predeposit.class.php
 * ....会员预存款操作类
 *
 * @copyright workflow_system 
 * @author workflow Develop Team 
 * @package 
 * @subpackage 
 * @version Mon Sep 01 15:28:06 CST 2008
 */

class PredepositClass extends FrameWork {
	/**
	 * 预存款列表
	 * @author  
	 * @param  
	 * @return array
	 */
	function listPredopesit($condition,&$obj_page){
		$conditionstr = $this->_conditionSearch($condition);
		$predopesit_array = $GLOBALS['db']->GetList($conditionstr, $obj_page, "predeposit_detail");
		return $predopesit_array;
	}
	
	/**
	 * 构造检索条件
	 * @author workflow Develop Team     
	 * @param  
	 * @return string
	 */
	function _conditionSearch($condition){
		$condition_str = "";
		
		//会员ID
		if ($condition['member_id'] != ''){
			if (is_array($condition['member_id'])){
				$condition_str .= " and (";
				foreach ($condition['member_id'] as $value){
					$line .= " or member_id = '" . intval($value) . "'";
				}
				$condition_str .= substr($line, 3).")";
				unset($line);
			}else {
				$condition_str .= " and member_id = '" . $condition['member_id'] . "'";
			}
		}
		//开始时间
		if ($condition['start_create_time'] != ''){
			$condition_str .= " and create_time >= '" . $condition['start_create_time'] . "'";
		}
		//结束时间
		if ($condition['end_create_time'] != ''){
			$condition_str .= " and create_time <= '" . $condition['end_create_time'] . "'";
		}
		//明细类别
		if ($condition['predeposit_type'] != ''){
			$condition_str .= " and predeposit_type = '" . $condition['predeposit_type'] . "'";
		}
		//明细状态
		if ($condition['predeposit_state'] != ''){
			$condition_str .= " and predeposit_state = '" . $condition['predeposit_state'] . "'";
		}
		//排序
		if ($condition['order_by'] != ''){
			$condition_str .= $condition['order_by'];
		}
		return $condition_str;
	}
	
	/**
	 * 增加充值记录
	 * @author workflow Develop Team     
	 * @param  
	 * @return bool
	 */
	function addPredepositRecord($param_array){
		if (is_array($param_array)){
			$value_array = array();
			foreach ($param_array as $k => $v){
				if ($v != ''){
					$value_array[$k] = $v;
				}
			}
			unset($param_array);
			$result = $GLOBALS['db']->InsertRow($value_array, 'predeposit_record', 'predeposit_r_id');
			return $result;
		}else {
			return false;
		}
	}
	
	/**
	 * 充值记录列表
	 * @author workflow Develop Team     
	 * @param  
	 * @return array
	 */
	function listPredepositRecord($condition,&$obj_page){
		$conditionstr = $this->_conditionSearchRecord($condition);
		$predopesit_array = $GLOBALS['db']->GetList($conditionstr, $obj_page, "predeposit_record");
		return $predopesit_array;
	}
	
	/**
	 * 构造充值信息检索条件
	 * @author workflow Develop Team     
	 * @param  
	 * @return int/bool/object/array
	 */
	function _conditionSearchRecord($condition){
		$condition_str = '';
		//会员ID
		if ($condition['member_id'] != ''){
			if (is_array($condition['member_id'])){
				$condition_str .= " and (";
				foreach ($condition['member_id'] as $value){
					$line .= " or member_id = '" . intval($value) . "'";
				}
				$condition_str .= substr($line, 3).")";
				unset($line);
			}else {
				$condition_str .= " and member_id = '" . $condition['member_id'] . "'";
			}
		}
		//创建时间
		if ($condition['create_time'] != ''){
			$condition_str .= " and create_time = '" . $condition['create_time'] . "'";
		}
		//开始时间
		if ($condition['start_create_time'] != ''){
			$condition_str .= " and create_time >= '" . $condition['start_create_time'] . "'";
		}
		//结束时间
		if ($condition['end_create_time'] != ''){
			$condition_str .= " and create_time <= '" . $condition['end_create_time'] . "'";
		}
		//充值方式
		if ($condition['payment'] != ''){
			$condition_str .= " and payment = '" . $condition['payment'] . "'";
		}
		//记录状态
		if ($condition['record_state'] != ''){
			$condition_str .= " and record_state = '" . $condition['record_state'] . "'";
		}
		//排序
		if ($condition['order_by'] != ''){
			$condition_str .= $condition['order_by'];
		}
		return $condition_str;
	}
	
	/**
	 * 取指定ID的充值信息
	 * @author workflow Develop Team     
	 * @param  $predeposit_r_id
	 * @return array
	 */
	function getOnePredepositRecordById($predeposit_r_id){
		if (intval($predeposit_r_id) > 0){
			$result = $GLOBALS['db']->GetOneRow($predeposit_r_id,'predeposit_record','predeposit_r_id');
			return $result;
		}else {
			return false;
		}
	}
	
	/**
	 * 根据支付平台流水号取充值信息
	 *
	 * @param int $payment_trade 
	 * @return array $rs_row 返回数组形式的查询结果
	 */
	function getOnePredepositRecordByTrade($payment_trade){
		$result = $GLOBALS['db']->GetOneRow($payment_trade,'predeposit_record','payment_trade');
		return $result;
	}
	
	/**
	 * 更新充值信息
	 * @author workflow Develop Team     
	 * @param  
	 * @return bool
	 */
	function updatePredepositRecord($param_array){
		if (is_array($param_array)){
			$value_array = array();
			foreach ($param_array as $k => $v){
				if ($v != ''){
					$value_array[$k] = $v;
				}
			}
			unset($param_array);
			$result = $GLOBALS['db']->UpdateRow($value_array['predeposit_r_id'],$value_array,'predeposit_record','predeposit_r_id');
			return $result;
		}else {
			return false;
		}
	}
	
	/**
	 * 增加预付款明细
	 * @author workflow Develop Team     
	 * @param  
	 * @return bool
	 */
	function addPredepositDetail($param_array){
		if (is_array($param_array)){
			$value_array = array();
			foreach ($param_array as $k => $v){
				if ($v != ''){
					$value_array[$k] = $v;
				}
			}
			unset($param_array);
			$result = $GLOBALS['db']->InsertRow($value_array, 'predeposit_detail', 'predeposit_id');
			return $result;
		}else {
			return false;
		}
	}
	
	/**
	 * 取指定ID的明细信息
	 * @author workflow Develop Team     
	 * @param  $predeposit_r_id
	 * @return array
	 */
	function getOnePredepositDetailById($predeposit_id){
		if (intval($predeposit_id) > 0){
			$result = $GLOBALS['db']->GetOneRow($predeposit_id,'predeposit_detail','predeposit_id');
			return $result;
		}else {
			return false;
		}
	}
	
	/**
	 * 提现明细列表
	 * @author workflow Develop Team     
	 * @param  
	 * @return array
	 */
	function listPredepositCash($condition,&$obj_page){
		$conditionstr = $this->_conditionSearchCash($condition);
		$predopesit_array = $GLOBALS['db']->GetList($conditionstr, $obj_page, "predeposit_cash");
		return $predopesit_array;
	}
	
	/**
	 * 构造提现信息检索条件
	 * @author workflow Develop Team     
	 * @param  
	 * @return int/bool/object/array
	 */
	function _conditionSearchCash($condition){
		$condition_str = "";
		
		//会员ID
		if ($condition['member_id'] != ''){
			if (is_array($condition['member_id'])){
				$condition_str .= " and (";
				foreach ($condition['member_id'] as $value){
					$line .= " or member_id = '" . intval($value) . "'";
				}
				$condition_str .= substr($line, 3).")";
				unset($line);
			}else {
				$condition_str .= " and member_id = '" . $condition['member_id'] . "'";
			}
		}
		//开始时间
		if ($condition['start_create_time'] != ''){
			$condition_str .= " and create_time >= '" . $condition['start_create_time'] . "'";
		}
		//结束时间
		if ($condition['end_create_time'] != ''){
			$condition_str .= " and create_time <= '" . $condition['end_create_time'] . "'";
		}
		//提现方式
		if ($condition['payment'] != ''){
			$condition_str .= " and payment = '" . $condition['payment'] . "'";
		}
		//记录状态
		if ($condition['record_state'] != ''){
			$condition_str .= " and record_state = '" . $condition['record_state'] . "'";
		}
		//排序
		if ($condition['order_by'] != ''){
			$condition_str .= $condition['order_by'];
		}
		return $condition_str;
	}
	
	/**
	 * 新增提现信息
	 * @author workflow Develop Team     
	 * @param  
	 * @return bool
	 */
	function addPredepositCash($param_array){
		if (is_array($param_array)){
			$value_array = array();
			foreach ($param_array as $k => $v){
				if ($v != ''){
					$value_array[$k] = $v;
				}
			}
			unset($param_array);
			$result = $GLOBALS['db']->InsertRow($value_array, 'predeposit_cash', 'predeposit_c_id');
			return $result;
		}else {
			return false;
		}
	}
	
	/**
	 * 取指定ID的提现信息
	 * @author workflow Develop Team     
	 * @param  $predeposit_r_id
	 * @return array
	 */
	function getOnePredepositCashById($predeposit_c_id){
		if (intval($predeposit_c_id) > 0){
			$result = $GLOBALS['db']->GetOneRow($predeposit_c_id,'predeposit_cash','predeposit_c_id');
			return $result;
		}else {
			return false;
		}
	}
	
	/**
	 * 更新提现信息
	 * @author workflow Develop Team     
	 * @param  
	 * @return bool
	 */
	function updatePredepositCash($param_array){
		if (is_array($param_array)){
			$value_array = array();
			foreach ($param_array as $k => $v){
				if ($v != ''){
					$value_array[$k] = $v;
				}
			}
			unset($param_array);
			$result = $GLOBALS['db']->UpdateRow($value_array['predeposit_c_id'],$value_array,'predeposit_cash','predeposit_c_id');
			return $result;
		}else {
			return false;
		}
	}
}
?>